<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="老人姓名" prop="elderlyName">
        <el-input
          v-model="queryParams.elderlyName"
          placeholder="请输入老人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="日期" prop="date">
        <el-date-picker
          v-model="queryParams.date"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
      v-if="refreshTable"
      v-loading="loading"
      :data="tableData"
      row-key="menuId"
    >
      <el-table-column prop="deviceCode" label="设备编码" :show-overflow-tooltip="true" minWidth="160"></el-table-column>
      <el-table-column prop="elderlyName" label="老人姓名" :show-overflow-tooltip="true" minWidth="160"></el-table-column>
      <el-table-column prop="heartRate" label="心率值" :show-overflow-tooltip="true" minWidth="160"></el-table-column>
      <el-table-column prop="bloodPressure" label="血压数值" :show-overflow-tooltip="true" minWidth="160"></el-table-column>
      <el-table-column prop="bloodOxygen" label="血氧数据" :show-overflow-tooltip="true" minWidth="160"></el-table-column>
      <el-table-column prop="temperature" label="体温监测" :show-overflow-tooltip="true" minWidth="160"></el-table-column>
      <el-table-column prop="activityTrajectory" label="活动轨迹" :show-overflow-tooltip="true" minWidth="160"></el-table-column>
      <el-table-column prop="remark" label="备注" :show-overflow-tooltip="true" minWidth="160"></el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { queryPage } from "@/api/pension/devicePushRecord";
import { queryList } from "@/api/pension/elderlyInfo";
import dayjs from "dayjs";

export default {
  name: "PushRecord",
  dicts: ['sys_normal_disable'],
  data() {
    return {
      total:0,
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 重新渲染表格状态
      refreshTable: true,
      // 查询参数
      queryParams: {
        elderlyName: '',
        date: [new Date(), new Date()],
      },
      tableData: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 远程搜索
    remoteMethod(query) {
      if (query !== '') {
        this.optionsLoading = true;
        queryList({name:query}).then(response => {
          this.options = response.data;
          this.optionsLoading = false;
        });
      } else {
        this.options = [];
      }
    },
    /** 查询菜单列表 */
    getList() {
      this.loading = true;
      const params = {}
      params.elderlyName = this.queryParams.elderlyName
      if (this.queryParams.date.length > 1) {
        params.createTimeStart = dayjs(this.queryParams.date[0]).startOf('day').format('YYYY-MM-DD HH:mm:ss')
        params.createTimeEnd = dayjs(this.queryParams.date[1]).endOf('day').format('YYYY-MM-DD HH:mm:ss')
      }
      queryPage(params).then(response => {
        this.tableData = response.data.list;
        this.total = response.data.totalCount;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
